<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>class实现继承</title>
</head>

<body>
  <h2>class实现继承</h2>
  <script>
    // 父类
    class Person {
      name
      constructor(name) {
        this.name = name
      }
      sayHi() {
        console.log('父类的sayHi')
      }
    }

    // ------------- 子类 -------------
    // extends: 继承父类
    // super: 一般用来调用父类的构造函数
    class Student extends Person {
      age
      constructor(name, age) {
        // 必须要调用super
        super(name)
        this.age = age
      }
      sayHello() {
        console.log('子类的sayHello')
      }
      // 同名方法，就近原则
      sayHi() {
        console.log('子类的sayHi')
      }
    }

    // const s = new Student('itheima')
    const s = new Student('itheima', 18)
  </script>
</body>

</html>